<?php 
defined('RUN_KATANA') or die('Restricted access');
require_once(MODEL_INCLUDE_PATH.'katana/KatanaCore.php');
if(defined('RUN_UPGRADE')) { require_once(MODEL_INCLUDE_PATH.'katana/KatanaUpgrade.php');}
class Katana
{
	public $Id;
	public $SiteId;
	public $URL;
	public $Version;
	public $Title;
	public $Language;
	public $MetaTitle;
	public $MetaData;
	public $MetaKey;
	public $HeaderItems;
	public $AnalyticsID;
	public $AnalyticsTrack;
	public $Active;
	public $ActiveCores;
	
	public $CompanyName;
	public $CompanyNumber;
	public $CompanyAddress;
	public $CompanyPhone;
	public $CompanyEmail;
	
	/* Display Defining Parameters */
	public $MenuID;
	public $OpenMenus;
	public $Breadcrumbs;
	public $ComID;
	public $ThemeID;
	public $Action;
	public $List;
	public $Edit;
	public $View;
	
	/* Display Object Defining Parameters */
	public $DetailView;
	public $VideoID;
	public $GalleryID;
	public $PlaylistID;
	public $ProductID;
	public $GroupID;
	public $ProviderID;
	public $SurveyID;
	public $ShipID;
	public $ShipNumber;
	
	public $HtmlID;
	public $ContentID;
	
	public $ProductsCount;
	public $TrackViews;
	
	public function Katana($Id) 
	{ 
		self::setId($Id); 
		self::setSiteId($Id); 
		self::loadActiveCores();
		self::loadValues();
		self::loadOpenMenus();
		self::setThemeID(THEME_ID);
	}
	
	/* GET FUNCTIONS */
	public function getId() { return intval($this->Id); }
	public function getSiteId() { return $this->SiteId; }
	public function getURL() { return $this->URL; }
	public function getVersion() { return intval($this->Version); }
	public function getTitle() { return $this->Title; }
	public function getLanguage() { return $this->Language; }
	public function getMetaTitle() { return $this->MetaTitle; }
	public function getMetaData() { return $this->MetaData; }
	public function getMetaKey() 
	{ 
		self::formatMetaKey();
		return $this->MetaKey; 
	}
	public function getHeaderItems() { return $this->HeaderItems; }
	
	public function getAnalyticsID() { return $this->AnalyticsID; }
	public function getAnalyticsTrack() 
	{ 
		if(UNIVERSAL_ANALYTICS)
		{
			//$katana->addAnalyticsTrack("_gaq.push(['_trackPageview', '/user/new/success']);");
			//ga('send', 'pageview', 'page path']);
			$this->AnalyticsTrack = str_replace("_gaq.push(['_trackPageview',", "ga('send', 'pageview',", $this->AnalyticsTrack);
			$this->AnalyticsTrack = str_replace(']', '', $this->AnalyticsTrack);
		}
		return $this->AnalyticsTrack; 
	}
	public function getActive() { return $this->Active; }
	public function getActiveCores() { return $this->ActiveCores; }
	
	public function getCompanyName() { return $this->CompanyName; }
	public function getCompanyNumber() { return $this->CompanyNumber; }
	public function getCompanyAddress() { return $this->CompanyAddress; }
	public function getCompanyPhone() { return $this->CompanyPhone; }
	public function getCompanyEmail() { return $this->CompanyEmail; }
	
	public function getMenuID() { return intval($this->MenuID); }
	public function getOpenMenus() { return $this->OpenMenus; }
	public function getBreadcrumbs() { return $this->Breadcrumbs; }
	public function getComID() { return intval($this->ComID); }
	public function getThemeID() { return intval($this->ThemeID); }
	public function getAction() { return $this->Action; }
	public function getList() { return $this->List; }
	public function getEdit() { return $this->Edit; }
	public function getView() { return $this->View; }
	
	public function getDetailView() { return $this->DetailView; }
	public function getAudioID() { return intval($this->AudioID); }
	public function getVideoID() { return intval($this->VideoID); }
	public function getGalleryID() { return intval($this->GalleryID); }
	public function getProductID() { return intval($this->ProductID); }
	public function getGroupID() { return intval($this->GroupID); }
	public function getProviderID() { return intval($this->ProviderID); }
	public function getSurveyID() { return intval($this->SurveyID); }
	public function getShipID() { return intval($this->ShipID); }
	public function getShipNumber() { return $this->ShipNumber; }
	
	public function getHtmlID() { return $this->HtmlID; }
	public function getContentID() { return $this->ContentID; }
	
	public function getProductsCount() { return $this->ProductsCount; }
	
	
	/* SET FUNCTIONS */
	public function setURL($val) { $this->URL=$val; }
	public function setVersion($val) { $this->Version=intval($val); }
	public function setTitle($val) { $this->Title=$val; }
	public function setMetaTitle($val) { $this->MetaTitle=$val; }
	public function setMetaData($val) { $this->MetaData=$val; }
	public function setMetaKey($val) { $this->MetaKey=$val; }
	
	public function setId($val) { $this->Id=intval($val); }
	public function setSiteId($val) { $this->SiteId=intval($val); }
	public function setLanguage($val) { $this->Language=$val; }
	public function setAnalyticsID($val) { $this->AnalyticsID=$val; }
	public function setAnalyticsTrack($val) { $this->AnalyticsTrack=$val; }
	public function setActive($val) { $this->Active=$val; }
	
	public function setCompanyName($val) { $this->CompanyName=$val; }
	public function setCompanyNumber($val) { $this->CompanyNumber=$val; }
	public function setCompanyAddress($val) { $this->CompanyAddress=$val; }
	public function setCompanyPhone($val) { $this->CompanyPhone=$val; }
	public function setCompanyEmail($val) { $this->CompanyEmail=$val; }
	
	public function setMenuID($val) { $this->MenuID=intval($val); }
	public function setOpenMenu($level, $id=0, $title='', $link='') 
	{ 
		$this->OpenMenus[$level]['id']=$id; 
		$this->OpenMenus[$level]['title']=$title;
		$this->OpenMenus[$level]['link']=$link; 
	}
	public function setBreadcrumb($level, $id=0, $title='', $link='') 
	{ 
		$this->Breadcrumbs[$level]['id']=$id; 
		$this->Breadcrumbs[$level]['title']=$title;
		$this->Breadcrumbs[$level]['link']=$link; 
	}
	
	public function setComID($val) { $this->ComID=intval($val); }
	public function setThemeID($val) { $this->ThemeID=intval($val); }
	public function setAction($val) { $this->Action=$val; }
	public function setList($val) { $this->List=$val; }
	public function setEdit($val) { $this->Edit=$val; }
	public function setView($val) { $this->View=$val; }
	
	public function setDetailView($val) { $this->DetailView=$val; }
	public function setAudioID($val) { $this->AudioID=intval($val); }
	public function setVideoID($val) { $this->VideoID=intval($val); }
	public function setGalleryID($val) { $this->GalleryID=intval($val); }
	public function setProductID($val) { $this->ProductID=intval($val); }
	public function setGroupID($val) { $this->GroupID=intval($val); }
	public function setProviderID($val) { $this->ProviderID=intval($val); }
	public function setSurveyID($val) { $this->SurveyID=intval($val); }
	public function setShipID($val) { $this->ShipID=intval($val); }
	public function setShipNumber($val) { $this->ShipNumber=$val; }
	
	public function setHtmlID($val) { $this->HtmlID=intval($val); }
	public function setContentID($val) { $this->ContentID=intval($val); }
	
	public function setProductsCount($val) { $this->ProductsCount=$val; }
	
	/* Make it find the right object */
	public function getRequestPath() {
		return $this->requestPath;
	}
	public function getRequestPagePath() {
		// I think the regexps take care of the trimming for us but just to be sure..
		$cPath = trim($this->cPath, '/');
		if ($cPath != '') {
			return '/' . $cPath;
		}
		return '';
	}
	public function getRequestPageID() {
		return $this->cID;
	}
	/** 
	 * Our new MVC way of doing things. Parses the collection path using like to find
	 * where the path stops and the parameters start. Enables us to use urls without a
	 * task/param separator in them
	 * @return Page
	 */
	public function getRequestedPage() 
	{
		$path = $this->getRequestCollectionPath();
		$origPath = $path;
		$r = array();
		$db = Loader::db();
		$cID = false;
		while ((!$cID) && $path) {
			$cID = $db->GetOne('select cID from PagePaths where cPath = ?', $path);
			if ($cID) 
			{
				$cPath = $path;
				break;
			}
			$path = substr($path, 0, strrpos($path, '/'));
		}		
		
		if ($cID && $cPath) 
		{ 
			$req = Request::get();
			$req->setCollectionPath($cPath);			
			$c = Page::getByID($cID, 'ACTIVE');
		} 
		else 
		{
			$c = new Page();
			$c->loadError(COLLECTION_NOT_FOUND);
		}
		return $c;
	}
	
	/**
	 * This is where we parse the path to see if it is a tool or page and if its a page
	 * get the task and parameters (if there are any)
	 * @access private
	 * @return void
	 */
	protected function parse()
	{
		
		$path = $this->requestPath;
		if (isset($_REQUEST['cID']) && intval($_REQUEST['cID']) > 0) 
		{ $this->cID = $_REQUEST['cID']; } 
		else 
		{ $this->cID = HOME_CID; }
		
		// home page w/param and task
		if (defined('ENABLE_LEGACY_CONTROLLER_URLS') && ENABLE_LEGACY_CONTROLLER_URLS == true) 
		{
			if (preg_match("/^\-\/(.[^\/]*)\/(.*)/i", $path, $matches)) 
			{
				$this->task = $matches[1];
				$this->params = $matches[2];
				return;
			}
	
			// home page w/just task
			if (preg_match("/^\-\/(.[^\/]*)/i", $path, $matches)) 
			{
				$this->task = $matches[1];
				return;
			}
	
			// path + task + params
			if (preg_match("/^(.*)\/\-\/(.[^\/]*)\/(.*)/i", $path, $matches)) 
			{
				$this->cPath = $matches[1];
				$this->task = $matches[2];
				$this->params = $matches[3];
				return;
			}
			
			// path + task
			if (preg_match("/^(.*)\/\-\/(.[^\/]*)/i", $path, $matches)) 
			{
				$this->cPath = $matches[1];
				$this->task = $matches[2];
				return;
			}
		}
		
		// tools

		$exploded = explode('/', $path);
		if($exploded[0] == 'tools') 
		{
			if($exploded[1] == 'blocks') 
			{
				$this->btHandle = $exploded[2];
				unset($exploded[0]);
				unset($exploded[1]);
				unset($exploded[2]);
				$imploded = implode('/', $exploded);
				if(substr($imploded, -4) == '.php') 
				{ $this->filename = $imploded; } 
				else 
				{ $this->filename = $imploded . '.php'; }
				$this->includeType = 'BLOCK_TOOL';
				return;
			}

			if($exploded[1] == 'css' && $exploded[2] == 'themes') 
			{
				unset($exploded[0]);
				unset($exploded[1]);
				unset($exploded[2]);
				$this->filename = 'css.php';
				$this->auxData = new stdClass;
				$this->auxData->theme = $exploded[3];
				unset($exploded[3]);
				$imploded = implode('/', $exploded);
				if(substr($imploded, -4) == '.css') 
				{ $this->auxData->file = $imploded; } 
				else 
				{ $this->auxData->file = $imploded . '.css'; }
				$this->includeType = 'CONCRETE_TOOL';
				return;
			}
			
			if($exploded[1] == 'packages') 
			{
				$this->pkgHandle = $exploded[2];
				unset($exploded[0]);
				unset($exploded[1]);
				unset($exploded[2]);
				$imploded = implode('/', $exploded);
				if(substr($imploded, -4) == '.php')
				{
					$this->filename = $imploded;
				} else {
					$this->filename = $imploded . '.php';
				}
				$this->includeType = 'PACKAGE_TOOL';
				return;
			}
			
			if($exploded[1] == 'required') 
			{
				unset($exploded[0]);
				unset($exploded[1]);
				$imploded = implode('/', $exploded);
				if(substr($imploded, -4) == '.php') 
				{ $this->filename = $imploded; } 
				else 
				{ $this->filename = $imploded . '.php'; }
				$this->includeType = 'CONCRETE_TOOL';
				return;
			}
			
			unset($exploded[0]);
			$imploded = implode('/', $exploded);
			if(substr($imploded, -4) == '.php') 
			{ $this->filename = $imploded; } 
			else
			{ $this->filename = $imploded . '.php'; }
			$this->includeType = 'TOOL';
			return;
		}
		// just path
		if ($path != '') {
			$this->cPath = $path;
			return;
		}		
	}
	/* Make it find the right object */
	
	public function getModPath($id=0)
	{
		if($id > 0)
		{
			$select = 'SELECT path FROM '.DB_PERFIX.'modules WHERE mod_id='.$id.' AND site_id='.self::getId().' AND active=1;';
			$result = mysql_query($select);
			while($row = mysql_fetch_array($result))
			{ $module['path'] = $row['path']; }
			if($module['path'] != '')
			{
				if(file_exists(TEMPLATES_PATH.'sites/'.self::getId().'/'.$module['path']))
				{ return 'templates/sites/'.self::getId().'/'.$module['path']; }
				else
				{ return $module['path']; }
			}
			else
			{
				$select = 'SELECT path FROM '.DB_PERFIX.'modules WHERE mod_id='.$id.';';
				$result = mysql_query($select);
				while($row = mysql_fetch_array($result))
				{ $module['path'] = $row['path']; }
				if($module['path'] != '')
				{
					if(file_exists(TEMPLATES_PATH.'sites/'.self::getId().'/'.$module['path']))
					{ return 'templates/sites/'.self::getId().'/'.$module['path']; }
					else
					{ return $module['path']; }
				}
			}
		}
		else
		{ return ''; }
	}
	
	public function loadActiveCores() 
	{ 
		global $db;
		if(self::getId() == 1)
		{ $sql  = 'SELECT * FROM '.DB_PERFIX.'katana_cores WHERE active=1;'; }
		else
		{
			$sql  = 'SELECT kc.*, sc.site_id ';
			$sql .= 'FROM '.DB_PERFIX.'katana_cores AS kc ';
			$sql .= 'LEFT JOIN '.DB_PERFIX.'site_cores AS sc ON sc.core_id=kc.id ';
			$sql .= 'WHERE sc.site_id='.self::getId().' AND sc.active=1;';
		}
		
		$result = $db->query($sql);
		$data = $db->fetch($sql, CACHE_TTL);
			
		if(is_array($data))
		{
			foreach($data as $row)
			{ 
				$this->ActiveCores[$row['id']] = new KatanaCore; 
				$this->ActiveCores[$row['id']]->setId($row['id']);
				$this->ActiveCores[$row['id']]->setTitle($row['title']);
				$this->ActiveCores[$row['id']]->setHandle($row['handle']);
				$this->ActiveCores[$row['id']]->setControllerClass($row['controllerClass']);
				$this->ActiveCores[$row['id']]->setVersion($row['version']);
			}
		}
	}
	
	public function loadValues() 
	{ 
		global $db;
		$sql  = 'SELECT * FROM '.DB_PERFIX.'sites WHERE id='.self::getId().' LIMIT 1;';
		
		$result = $db->query($sql);
		$data = $db->fetch($sql, CACHE_TTL);
		
		if(is_array($data))
		{
			foreach($data as $row)
			{ 
				self::setTitle($row['title']);
				self::setURL($row['site_url']);
				self::setVersion($row['Version']); 
				self::setLanguage($row['language']); 
				self::setMetaTitle($row['MetaTitle']);
				self::setMetaData($row['meta_data']);
				self::setMetaKey($row['meta_key']);
				self::setAnalyticsID($row['analytics_id']);
				self::setActive($row['active']);
				self::setCompanyName($row['company_name']);
				self::setCompanyNumber($row['company_number']);
				self::setCompanyAddress($row['company_address']);
				self::setCompanyPhone($row['company_phone']);
				self::setCompanyEmail($row['company_email']);
			}
		}
		
		if($_REQUEST['m'] > 0)
		{ self::setMenuID($_REQUEST['m']); }
		
		if($_REQUEST['action'] != '')
		{ self::setAction($_REQUEST['action']); }
		
		if(intval($_REQUEST['c']) > 0)
		{ self::setComID(intval($_REQUEST['c'])); }
		
		if(intval($_REQUEST['t']) > 0)
		{ self::setThemeID(intval($_REQUEST['t'])); }
		
		if(($_REQUEST['g'] > 0) && ($this->ActiveCores[2]))
		{ 
			self::setGalleryID($_REQUEST['g']); 
			self::setDetailView(true);
		}
		if(($_REQUEST['v'] > 0) && ($this->ActiveCores[3]))
		{ 
			self::setVideoID($_REQUEST['v']); 
			self::setDetailView(true);
		}
		if(($_REQUEST['a'] > 0) && ($this->ActiveCores[4]))
		{ 
			self::setAudioID($_REQUEST['a']); 
			self::setDetailView(true); 
		}
		if((intval($_REQUEST['p']) > 0) && ($this->ActiveCores[8]))
		{ 
			self::setProductID(intval($_REQUEST['p']));
			self::setDetailView(true); 
		}
		if((intval($_REQUEST['g']) > 0) && ($this->ActiveCores[8]))
		{ 
			self::setGroupID(intval($_REQUEST['g']));
			self::setDetailView(true); 
		}
		if((intval($_REQUEST['provider']) > 0) && ($this->ActiveCores[8]))
		{ 
			self::setProviderID(intval($_REQUEST['provider']));
			self::setDetailView(true); 
		}
		if((intval($_REQUEST['s']) > 0) && ($this->ActiveCores[9]))
		{ 
			self::setSurveyID(intval($_REQUEST['s']));
			self::setDetailView(true); 
		}
		if(($_REQUEST['ship'] > 0) && ($this->ActiveCores[10]))
		{ 
			self::setShipNumber($_REQUEST['ship']);
			self::setDetailView(true); 
		}
		if($_REQUEST['list'] != '')
		{ 
			self::setList(trim($_REQUEST['list']));
			switch(self::getList())
			{
				case 'providers': break;
				case 'brandproviders': break;
				case 'productgroups': break;
				case 'ad': break;
				case 'search': break;
				case 'bookmark': break;
				case 'profile': break;
				default: self::setList('');
			}
		}
		if($_REQUEST['edit'] != '')
		{ self::setEdit(trim($_REQUEST['edit'])); }
		if($_REQUEST['view'] != '')
		{ self::setView(trim($_REQUEST['view'])); }
	}
	
	public function reloadValues() 
	{
		if(!$this->DetailView)
		{ self::getItemsCount(); }
	}
	
	public function loadOpenMenus($start=0, $level=0) 
	{ 
		if($start == 0)
		{ $start = self::getMenuID(); }
		
		if($start > 0)
		{ $where = 'id='.$start.' AND active=1 AND site_id='.self::getId(); }
		else
		{ $where = 'frontpage=1 AND active=1 AND site_id='.self::getId(); }
		
		if($start == self::getMenuID())
		{ $select = 'id, parent_id, frontpage, title, visible, theme_id, MetaTitle, link_type, link_id, link_url'; }
		else
		{ $select = 'id, parent_id, frontpage, title, visible, theme_id, MetaTitle'; }
		
		$sql = 'SELECT '.$select.' FROM '.DB_PERFIX.'sitemap_pages WHERE '.$where.' LIMIT 1;';
		
		$result = mysql_query($sql);
		if($result)
		{
			while($row = mysql_fetch_array($result))
			{ 
				if((self::getMenuID() == 0) && ($row['frontpage'] == 1))
				{ self::setMenuID($row['id']); }
				
				if($row['visible'] > 0)
				{ self::setOpenMenu($level, $row['id'], $row['title']); }
				
				if(($row['frontpage'] == 1) && ($row['MetaTitle'] == ''))
				{ self::addAfterMetaTitle(self::getMetaTitle()); }
				else
				{ self::addAfterMetaTitle(self::getTitle()); }
				
				if((self::getMenuID() == $row['id']) && ($row['MetaTitle'] != ''))
				{ self::setMetaTitle($row['MetaTitle']); }
				
				if(self::getMetaData() == '')
				{ self::addBeforeMetaData($row['title']); }
				self::addBeforeMetaKey($row['title']);
				
				if(($row['theme_id'] > 0) && (!($this->ThemeID > 0)))
				{ self::setThemeID($row['theme_id']); }
				
				if($row['parent_id'] > 0)
				{ self::loadOpenMenus($row['parent_id'], ($level+1)) ; }
				else
				{
					if(is_array($this->OpenMenus))
					{ 
						$this->OpenMenus = array_reverse($this->OpenMenus); 
						$this->Breadcrumbs = $this->OpenMenus;
					}
				}
				
				if($start == self::getMenuID())
				{
					self::setHtmlID($row['id']);
					if(($row['link_type'] == 3) && ($row['link_id'] > 0))
					{ self::setContentID($row['link_id']); }
				}
			}
		}
	}
	
	public function getItemsCount()
	{
	}
	
	public function viewFrontpage()
	{
		$fp = true;
		/*
		if($this->MenuID > 0)
		{ $fp = false; }
		*/
		if(self::getComID() > 0)
		{ $fp = false; }
		if($this->SurveyID > 0)
		{ $fp = false; }
		if($this->ShipNumber > 0)
		{ $fp = false; }
		if(self::getDetailView())
		{ $fp = false; }
		if(self::getList() != '')
		{ $fp = false; }
		return $fp;
	}
	
	public function getFormAction()
	{
		if(self::getMenuID() > 0)
		{ 
			if(URL_REWRITE == true)
			{ $action = SITE_URL.'m/'.self::getMenuID().'/?'; }
			else
			{ $action = SITE_URL.'?m='.self::getMenuID().'&amp;'; }
		}
		else
		{ $action = SITE_URL.'?m='.self::getMenuID().'&amp;'; }
		
		if(self::getComID() > 0)
		{ 
			if(URL_REWRITE == true)
			{ $action = SITE_URL.'c/'.self::getComID().'/?'; }
			else
			{ $action = SITE_URL.'?c='.self::getComID().'&amp;'; }
		}
		if($this->SurveyID > 0)
		{ $action .= 's='.$this->SurveyID.'&amp;';}
		if($this->ShipNumber > 0)
		{ $action .= 'ship='.$this->ShipNumber.'&amp;'; }
		if(self::getEdit() != '')
		{ $action .= 'edit='.self::getEdit().'&amp;'; }
		if(self::getList() != '')
		{ $action .= 'list='.self::getList().'&amp;'; }
		if(self::getView() != '')
		{ $action .= 'view='.self::getView().'&amp;'; }
		return $action;
	}
	
	public function addAnalyticsTrack($val = '')
	{
		if($val != '')
		{
			if($this->AnalyticsTrack != '')
			{ self::setAnalyticsTrack($val.' '.$this->AnalyticsTrack); }
			else
			{ self::setAnalyticsTrack($val); }
		}
	}
	
	public function addBeforeMetaTitle($val) 
	{
		if($val != '')
		{
			if($this->MetaTitle != '')
			{ self::setMetaTitle($val.' - '.$this->MetaTitle); }
			else
			{ self::setMetaTitle($val); }
		}
	}
	
	public function addAfterMetaTitle($val) 
	{ 
		if($val != '')
		{
			if($this->MetaTitle != '')
			{ self::setMetaTitle($this->MetaTitle.' - '.$val); }
			else
			{ self::setMetaTitle($val); }
		}
	}
	public function addHeaderItem($item) 
	{ 
		if($item != '')
		{ $this->HeaderItems = $this->HeaderItems.$item; }
	}
	
	public function addBeforeMetaData($val) 
	{ self::setMetaData($val.' - '.$this->MetaData); }
	
	public function addBeforeMetaKey($val) 
	{ self::setMetaKey($val.', '.$this->MetaKey); }
	
	public function formatMetaKey()
	{
		if($this->MetaKey != '')
		{
			$this->MetaKey = trim(strtolower($this->MetaKey));
			$words = explode(' ', $this->MetaKey);
			if(count($words) > 0)
			{ $this->MetaKey =  implode(", ", $words); }
			$this->MetaKey = str_ireplace(',,',',',$this->MetaKey);
		}
	}
	
	public function recordTrackViews() 
	{ 
		if(is_array($this->TrackViews))
		{
			foreach($this->TrackViews as $table)
			{
				if(is_array($table))
				{
					foreach($table as $view)
					{
						if(($view['table'] != '') && ($view['where'] != '') && ($view['set'] != ''))
						{
							$sql = 'UPDATE '.DB_PERFIX.$view['table'].' SET '.$view['set'].' WHERE '.$view['where'].';';
							$result = mysql_query($sql);
						}
					}
				}
			}
		}
	}
	
	public function getCompanyMailFooter($fontstyle = '')
	{
		global $txt;
		$output = '<p style="'.$fontstyle.'">';
		$output .= self::getCompanyName().'<br />';
		$output .= self::getCompanyAddress().'<br />';
		$output .= 'Tel: '.self::getCompanyPhone().'<br />';
		$output .= ucfirst($txt->getWord('e-mail')).': '.self::getCompanyEmail().'<br />';
		$output .= '</p>';
		return $output;
	}
	
	public function cronHour()
	{
		$out = '';
		$out .= self::clearCache();
		return $out;
	}
	
	public function clearCache()
	{
		$out .= 'ClearingCache<br />';
		$files = scandir(CACHE_PATH);
		if(is_array($files))
		{
			$out .= 'Found '.(count($files)-2).' files.<br />';
			$deleted = 0;
			foreach($files as $file)
			{
				if(($file != '..') && ($file != '.'))
				{
					if(is_file(CACHE_PATH.$file))
					{
						$ts = filemtime(CACHE_PATH.$file);
						$tl = (time() - $ts);
						if($tl > CACHE_TTL)
						{
							echo '$tl:'.$tl.' - ';
							echo 'Deleting:'.$file;
							unlink(CACHE_PATH.$file);
							$deleted++;
							echo ' - '.$deleted.' - Ok<br />';
						}
					}
				}
			}
			$out .= 'Deleted '.$deleted.' cache files.<br />';
		}
		unset($files);
		
		$deleted = 0;
		$out .= 'ClearingCachedThumbnails<br />';
		$files = scandir(ADS_THUMB_PATH);
		if(is_array($files))
		{
			$out .= 'Found '.(count($files)-2).' files.<br />';
			$deleted = 0;
			foreach($files as $file)
			{
				if(($file != '..') && ($file != '.'))
				{
					if(is_file(ADS_THUMB_PATH.$file))
					{
						$ts = filemtime(ADS_THUMB_PATH.$file);
						$tl = (time() - $ts);
						if($tl > (86400 * 30)) //older than 30 days
						{
							switch($file)
							{
								case 'index.html':
								break;
								default:
									echo '$tl:'.$tl.' - ';
									echo 'Deleting:'.$file;
									unlink(ADS_THUMB_PATH.$file);
									$deleted++;
									echo ' - '.$deleted.' - Ok<br />';
								break;
							}
						}
					}
				}
			}
			$out .= 'Deleted '.$deleted.' CachedThumbnails.<br />';
		}
		unset($files);
		return $out;
	}
}
?>